from kafka import KafkaProducer

if __name__ == '__main__':
    # 创建生产者
    producer = KafkaProducer(bootstrap_servers="master:9092,node1:9092,node2:9092")

    # 读取文件
    with open("../data/students.txt", mode="r", encoding="UTF-8") as file:
        cars = file.readlines()

    # 循环将数据写入kafka
    for car in cars:
        # 发送数据到kafka
        producer.send(topic="student", value=car.strip().encode("UTF-8"))
        producer.flush()

    producer.close()
